fix toOsPath on windows
authorJoey Hess <joeyh@joeyh.name>
Wed, 29 Jan 2025 18:06:54 +0000 (14:06 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 29 Jan 2025 18:06:54 +0000 (14:06 -0400)
After recent changes to use OsPath, test suite fails on windows with:

Exception: Uneven number of bytes: 5. This is not a Word16 bytestream.

Hopefully this fixes it. The innefficiency of the conversion is
unfortunate.

Utility/OsPath.hs

index 5a62e61004dea1fcffede3dd1fc3f5d2da29f8b2..bd7baf85eb3c82c9f717bf732d8c71ec32626ae4 100644 (file)
@@ -22,13 +22,16 @@ import Utility.FileSystemEncoding
 import System.OsPath
 import "os-string" System.OsString.Internal.Types
 import qualified Data.ByteString.Short as S
+#if defined(mingw32_HOST_OS)
+import GHC.IO (unsafePerformIO)
+#endif
 
-{- Unlike System.OsString.fromBytes, on Windows this does not ensure a
- - valid USC-2LE encoding. The input ByteString must be in a valid encoding
- - already or uses of the OsPath will fail. -}
 toOsPath :: RawFilePath -> OsPath
 #if defined(mingw32_HOST_OS)
-toOsPath = OsString . WindowsString . S.toShort
+-- On Windows, OsString contains a ShortByteString that is
+-- utf-16 encoded. So have to convert the input to that.
+-- This is relatively expensive.
+toOsPath = unsafePerformIO . encodeFS . fromRawFilePath
 #else
 toOsPath = OsString . PosixString . S.toShort
 #endif